{% from "dockers/dockerfile-macros.j2" import install_debian_packages %}
ARG BASE=docker-config-engine-bookworm-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}

FROM $BASE AS base

ARG docker_container_name

## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive

## Pre-install the fundamental packages
RUN apt-get update \
 && apt-get -y install  \
    gdb                 \
    libboost-atomic1.74.0 \
    libqt5core5a          \
    libqt5network5      \
    libyaml-dev         \
    libthrift-0.17.0    \
    binutils

RUN pip3 install numpy
RUN pip3 install yamlordereddictloader

COPY \
{% for deb in docker_saiserver_mrvl_teralynx_debs.split(' ') -%}
debs/{{ deb }}{{' '}}
{%- endfor -%}
debs/

RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; } ; \
{% for deb in docker_saiserver_mrvl_teralynx_debs.split(' ') -%}
dpkg_apt debs/{{ deb }}{{'; '}}
{%- endfor %}

COPY ["start.sh", "/usr/bin"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]

## Clean up
RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
RUN rm -rf /debs

FROM $BASE

RUN --mount=type=bind,from=base,target=/changes-to-image rsync -axAX --no-D --exclude=/sys --exclude=/proc --exclude=/dev --exclude=resolv.conf /changes-to-image/ /

ENV DEBIAN_FRONTEND=noninteractive
ENTRYPOINT ["/usr/local/bin/supervisord"]
